package java3_29;


import java.util.HashMap;
import java.util.*;
import java.util.Scanner;

/**
 * 输入一个字符串，分割每个字符，统计他们出现的次数，存入Map(key为string或者Char,value为次数)
 * 输出是按照出现次数从多到少。
 * 例如输入 一只小小狗，则输出如下（次数相同，顺序随意）
 *  小  2
 *  狗  1
 *  一  1
 *  只  1
 */
public class MapHomework {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.next();
        Map<Character,Integer> map = new HashMap<>();
        for (int i = 0; i < str.length(); i++) {
            Character s = str.charAt(i);
            if (map.containsKey(s)){
                map.put(s,map.get(s)+1);
            }else {
                map.put(s,1);
            }
        }

        Set<Map.Entry<Character, Integer>> entries = map.entrySet();
        ArrayList<Map.Entry<Character, Integer>> list = new ArrayList<>();
        list.addAll(entries);
        Collections.sort(list,new comp());
        System.out.println(list);
    }
}
class comp implements Comparator <Map.Entry<Character, Integer>>{

    @Override
    public int compare(Map.Entry<Character, Integer>o1, Map.Entry<Character, Integer>o2) {
        return o2.getValue()- o1.getValue();
    }
}
